#!/bin/bash

# 定义变量
IMAGE_NAME="vue2_admin_template"
IMAGE_TAG="latest"
COMPOSE_FILE="docker-compose.yml"
SERVICE_NAME="vue2_admin_template"

# 步骤1：构建Docker镜像
echo "开始构建Docker镜像..."
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .

# 检查构建是否成功
if [ $? -ne 0 ]; then
    echo "镜像构建失败!"
    exit 1
fi

echo "镜像构建成功: ${IMAGE_NAME}:${IMAGE_TAG}"

# 步骤2：使用docker-compose启动服务
echo "启动Docker Compose服务..."
docker compose -f ${COMPOSE_FILE} up -d ${SERVICE_NAME}

# 检查服务是否启动成功
if [ $? -ne 0 ]; then
    echo "服务启动失败!"
    exit 1
fi

echo "服务启动成功!"
echo "使用以下命令查看日志: docker-compose -f ${COMPOSE_FILE} logs -f ${SERVICE_NAME}"
